package com.socket.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class MidSocket {

	public static void connect() throws UnknownHostException, IOException {
		// 3191674B1EEDAA7EDD8289B91C13EB55

		Socket socket = new Socket("61.148.100.234", 3389);
		System.out.println("创建成功.....");

		BufferedReader is = new BufferedReader(new InputStreamReader(
				socket.getInputStream()));
		PrintWriter os = new PrintWriter(socket.getOutputStream());

		os.write("");
		String readline;
		readline = is.readLine(); // 从系统标准输入读入一字符串
		while (null != readline) {
			readline = is.readLine();
			break;
		}
		os.close();
		is.close();
		socket.close();
	}

	public static void testNetwork() throws UnknownHostException, IOException {

		while (true) {

			long start = System.currentTimeMillis();
			Socket socket = new Socket("218.17.160.130", 8000);
			long end = System.currentTimeMillis();
			socket.close();
			System.out.println("     " + (end - start));
		}

	}

	public static void main(String[] args) throws UnknownHostException,
			IOException {
		MidSocket.testNetwork();
	}
}
